package com.wcgksoft.controller.user;

import com.wcgksoft.common.util.Layui;
import com.wcgksoft.entity.system.SysUser;
import com.wcgksoft.service.system.UserService;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("systemuser")
public class systemUserController {

    @Autowired
    private UserService userService;

    /**
     * 添加或者修改信息的方法
     *
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public Layui update(ModelMap modelMap,
                        @RequestParam(value = "data", required = false) String data) {
        JSONObject param = JSONObject.fromObject(data);
        if (param == null) {
            return Layui.data(1, "请求格式有误", 0, null);
        } else {
            SysUser sysUser = (SysUser) JSONObject.toBean(JSONObject.fromObject(data), SysUser.class);
            //goodsType.setCreateTime(new Date());
            userService.saveOrUpdate(sysUser);
            return Layui.data(0, "个人信息保存成功", 1, Layui.addList(sysUser));
        }
    }

}
